package com.roger.tool.utils.mm;

import android.content.Context;

import com.roger.tool.SGLog;


/**
 * 获取MM 相关信息
 * @author lch
 *
 */
public class MmInfos {
	
	private static MmInfos mMmInfos;
	
	private String mmAppid = "";
	private String mmChannel = "";
	
	/**
	 * mm AppId,获取不到时 是 “”
	 * @return
	 */
	public String getMmAppid() {
		return mmAppid;
	}

	/**
	 * mm Channel,获取不到时 是“”
	 * @return
	 */
	public String getMmChannel() {
		return mmChannel;
	}
	

	public void setMmAppid(String mmAppid) {
		this.mmAppid = mmAppid;
	}

	public void setMmChannel(String mmChannel) {
		this.mmChannel = mmChannel;
	}

	private MmInfos(Context pContext){
		this.init(pContext);
	}
	
	public static MmInfos getInstance(Context pContext){
		if(mMmInfos==null){
			MmInfos.mMmInfos = new MmInfos(pContext);
		}
		return MmInfos.mMmInfos;
	}
	
	private void init(Context pContext) {
		if(pContext!=null){
			this.mmAppid = this.getMmAppId(pContext);
			this.mmChannel = this.getMmChannel(pContext);
		}
		
		// 约定好 取不到任何一个，两个都设为 “”
		if(this.mmAppid == null || this.mmChannel==null){
			this.mmAppid = "";
			this.mmChannel = "";
		}
		
		String msg2 = "MmInfos---> mmAppid =  " + mmAppid + "\n";
		msg2 += "mmChannel = " + mmChannel;
		SGLog.d(msg2);

	}
	
	/**
	 * 获取 MM 渠道
	 * @return
	 */
	private String getMmChannel(Context pContext){
		
		String channel = "";
		try {
			String mmmapxml =  ApkUtils.readXml(pContext, pContext.getPackageName(), "mmiap.xml");
			channel = MyXmlParser.getChannel(mmmapxml);
		} catch (Exception e) { 
//			e.printStackTrace();
		}
		
		return channel;
	}
	
	/**
	 * 获取MM AppId
	 * @param pContext
	 * @return
	 */
	private String getMmAppId(Context pContext){
		
		String appId = "";
		try {
			String copyrxml = ApkUtils.readXml(pContext, pContext.getPackageName(), "CopyrightDeclaration.xml");
			appId = MyXmlParser.getAppId(copyrxml);
		} catch (Exception e) {
//			e.printStackTrace();
		}
		
		return appId;
	}

}
